//
// Created by guo on 24-4-25.
//
#include <iostream>
#include <boost/asio.hpp>
#include <thread>
#include <chrono>
#include <opencv4/opencv2/opencv.hpp>
#include "loader.h"
#include "struct.h"

int main(){//"127.0.0.1"
    boost::asio::io_service io_service;
    boost::asio::ip::udp::endpoint local_endpoint(boost::asio::ip::address::from_string("127.0.0.1"),8888);
    boost::asio::ip::udp::endpoint remote_endpoint(boost::asio::ip::address::from_string("127.0.0.1"),9999);
    boost::asio::ip::udp::socket socket(io_service,local_endpoint);

    std::vector<std::string> files;
    search_dir("/home/guo/work/cpp/SynergyDemo/data/",files);

    uint32_t i = 0;
    for(const auto& file : files){
        if(i%2 == 1){
            //todo 检测生成box
            std::this_thread::sleep_for(std::chrono::milliseconds(2000));
            std::cout << "detecting file " << file << std::endl;
            Box box{
                    10,10,50,50,i,0,1.0
            };

            cv::Mat img = cv::imread(files[box.id]);
            cv::Rect rect(box.x,box.y,box.w,box.h);
            cv::Mat cut = img(rect);

            cv::imshow(files[box.id],cut);
            cv::waitKey(500);


            socket.send_to(boost::asio::buffer(&box,sizeof(Box)),remote_endpoint);
        }
        i++;
    }

    socket.close();
    return EXIT_SUCCESS;
}